package com.bwf.dao;

import com.bwf.pojo.Cla;
import com.bwf.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/2 9:58
 * @Copyright 博为峰
 */
public class ClaDaoImpl implements ClaDao {

    @Override
    public ArrayList<Cla> select() throws SQLException {
        Connection connection = DBUtil.getConn();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from t_class");
        ResultSet resultSet = preparedStatement.executeQuery();
        ArrayList<Cla> list = new ArrayList<>();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int num = resultSet.getInt("num");
            Cla cla = new Cla(id, name, num);
            list.add(cla);
        }
        return list;
    }
}
